﻿using System;
using Game1942.Library.Background;
using Game1942.Library.Background.Bodies;

namespace Game1942.Library.Items
{
    public class AmmoPackage : ComputerElement
    {
        private Body body;
        private int lifeTime = Constants.AmmoPackage.LifeTime;

        // Constructor
        public AmmoPackage(Point value)
        {
            body = new Square(Constants.AmmoPackage.Width, Constants.AmmoPackage.Height);
            position.SetBody(body);
            position.InitializeLocation(value);
        }

        
        // Getters

        public int AmountOfRockets
        {
            get { return Constants.AmmoPackage.AmmountOfRockets; }
        }

        public int AmountOfTorpedos
        {
            get { return Constants.AmmoPackage.AmmountOfTorpedos; }
        }

        public override void CrashWith(Element intruder)
        {
            var player = Driver.Instance.Player;
            if (ReferenceEquals(intruder, player))
            {
                player.ReloadWeapons(this);
                Destroy();
            }
        }

        public override bool IsEnemy(Element intruder)
        {
            return (ReferenceEquals(intruder, Driver.Instance.Player));
        }

        public override bool IsEnemy(bool playerteam)
        {
            return false;
        }

        public override int HarmSomebody(int enemyEnergy)
        {
            return enemyEnergy;
        }

        public override void Live()
        {
            if (lifeTime == 0)
            {
                Alive = false;
            }
            lifeTime--;
        }

        public override void Destroy()
        {
            position.Deallocate();  // If it is on the map, get rid of it
            Alive = false;
        }
    }
}
